/*
 ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1

 * The contents of this file are subject to the Mozilla Public License Version 
 * 1.1 (the "License"); you may not use this file except in compliance with 
 * the License. You may obtain a copy of the License at 
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Blazing Games Inc. (Billy D. Spelchan) code.
 *
 * The Initial Developer of the Original Code is
 * Blazing Games Inc.
 * Portions created by the Initial Developer are Copyright (C) 1999, 2003, 2005-2006
 * the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s):
 *
 ***** END LICENSE BLOCK *****
 */
package com.blazinggames.holeman;

//import java.applet.*;
import java.awt.*;
//import java.awt.image.*;
import java.awt.event.*;


public class SpeedSelect
extends Panel
implements MouseListener, MouseMotionListener {
// *** CONSTANTS ***
  final static Font fontBIG = new Font("TimesRoman", Font.BOLD, 32);

  final static Color colorTITLE = new Color(128, 128, 128);
  final static Color colorOPTION = new Color(0, 128, 0);
  final static Color colorSELECTED = new Color(0, 255, 0);

  final static String sTITLE = "Select Speed:";
  final static String sOPTIONS[] = {
    "Fast", "Normal", "Slow", "Slowest"
  };

  // *** VARIABLES ***
	ActionListener eventActionListener;

  int nLastSpeed, nCurSpeed;

// *** CONSTRUCTORS ***
	public SpeedSelect(ActionListener al) {
		addMouseListener(this);
    addMouseMotionListener(this);
    eventActionListener = al;
    setBackground(Color.black);
	}

  public int getSpeed() {
    if ((nCurSpeed < 1) || (nCurSpeed > 4))
      return 2;
    else
      return nCurSpeed;
  }


	public void paint(Graphics g) {
    int cntr;
    Color oldColor = g.getColor();
    Font oldFont = g.getFont();

    g.setFont(fontBIG);
    FontMetrics fm = g.getFontMetrics();

    g.setColor(colorTITLE);
    g.drawString(sTITLE, 320 - (fm.stringWidth(sTITLE) >> 1), 50);

    for (cntr = 0; cntr < sOPTIONS.length; ++cntr) {
      if (cntr == (nCurSpeed-1))
        g.setColor(colorSELECTED);
      else
        g.setColor(colorOPTION);
      g.drawString(sOPTIONS[cntr], 320 - (fm.stringWidth(sOPTIONS[cntr]) >> 1), 50*cntr+100);
    }

    g.setFont(oldFont);
    g.setColor(oldColor);
    nLastSpeed = nCurSpeed;
	}

// *** MOUSE EVENTS ***
  /**
    Mouse Clicked event from MouseListener.
    Invoked when the mouse has been clicked on a component.
  */
  public void mouseClicked(MouseEvent e) { /* ignore */ }

  /**
    mousePressed event from MouseListener.
    Invoked when a mouse button has been pressed on a component.
  */
  public void mousePressed(MouseEvent e) { /* ignore */ }

 /**
    mouseReleased event from MouseListener.
    Invoked when a mouse button has been released on a component.
  */
  public void mouseReleased(MouseEvent e) {
    eventActionListener.actionPerformed(
          new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Next"));
  }

  /**
    mouseEntered event from MouseListener.
    Invoked when the mouse enters a component.
  */
  public void mouseEntered(MouseEvent e) { /* ignore */ }

 /**
    mouseExited event from MouseListener.
    Invoked when the mouse exits a component.
  */
  public void mouseExited(MouseEvent e) { /* ignore */ }

  /**
    mouseDragged event from MouseMotionListener.
    Invoked when a mouse button is pressed on a component and then dragged.
    Mouse drag events will continue to be delivered to the component where the
    first originated until the mouse button is released (regardless of whether
    the mouse position is within the bounds of the component).
  */
  public void mouseDragged(MouseEvent e) {
    /* ignore */
  }

  /**
    mouseMoved event from MouseMotionListener.
    Invoked when the mouse button has been moved on a component (with no buttons no down).
  */
  public void mouseMoved(MouseEvent e) {
    nCurSpeed = e.getY() / 50;
    if (nCurSpeed != nLastSpeed)
      repaint();
  }

}
